View Javadoc

1   /*
2    * Created on 30-May-2005
3    *
4    * @todo To change the template for this generated file go to
5    * Window - Preferences - Java - Code Style - Code Templates
6    */
7   package uk.ac.roe.antigen.dialogs;
8   
9   import java.awt.Dimension;
10  import java.awt.Point;
11  import java.awt.Toolkit;
12  
13  import javax.swing.JFrame;
14  
15  /***
16   *
17   * Centers a given frame.  Surely there's a better way?
18   * @author Jon Tayler johndavidtaylor@users.sourceforge.net
19   * 
20   */
21  public class FrameCenterer {
22  
23      private JFrame theFrame;
24  
25      /***
26       * 
27       */
28      public FrameCenterer(JFrame theFrame) {
29          this.theFrame = theFrame;
30      }
31  
32      public void center() {
33          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
34          Dimension d = theFrame.getSize();
35          int x = (screenSize.width - d.width) / 2;
36          int y = (screenSize.height - d.height) / 2;
37          Point pt = new Point(x, y);
38          theFrame.setLocation(pt);
39      }
40  }